package com.ruoyi.web.controller.car;


import com.ruoyi.car.business.domain.Appointment;
import com.ruoyi.car.business.domain.Statement;
import com.ruoyi.car.business.query.AppointmentQuery;
import com.ruoyi.car.business.service.IAppointmentService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TablePageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 岗位控制器
 */
@RestController
@RequestMapping("business/appointment")
public class AppointmentController {
    private String prefix = "business/appointment";
    @Autowired
    private IAppointmentService appointmentService;
    @RequiresPermissions("business:appointment:view")
    @GetMapping()
    public String appointment()
    {
        return prefix + "/appointment";
    }


    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("business:appointment:list")
    @PostMapping("/query")
    @ResponseBody
    public TablePageInfo<Appointment> query(AppointmentQuery qo){
        return appointmentService.query(qo);
    }

    //新增
    @RequiresPermissions("business:appointment:add")
    @RequestMapping("/add")
    public AjaxResult addSave(Appointment appointment){
        appointmentService.save(appointment);
        return AjaxResult.success();
    }

    //编辑
    @RequiresPermissions("business:appointment:edit")
    @RequestMapping("/edit")
    public AjaxResult edit(Appointment appointment){
        appointmentService.update(appointment);
        return AjaxResult.success();
    }

    //用户到店操作
    @RequestMapping("/arrival")
    public AjaxResult arrival(Long id){
        appointmentService.arrival(id);
        return AjaxResult.success();
    }

    //删除
    @RequestMapping("/remove")
    public AjaxResult remove(String ids){
        appointmentService.deleteBatch(ids);
        return AjaxResult.success();
    }

    //取消养修预约
    @RequestMapping("/cancel")
    public AjaxResult cancel(Long id){
        appointmentService.cancel(id);
        return AjaxResult.success();
    }

    // 生成结算单
    @RequestMapping("/generateStatement")
    public AjaxResult generateStatement(Long appointmentId){
        Statement statement = appointmentService.generateStatement(appointmentId);
        return AjaxResult.success(statement.getId());
    }
}
